import 'package:aio/aio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:app/generated/app_strings.dart';
import 'package:app/src/http/bean/wroks/attachment_bean.dart';
import 'package:app/src/http/bean/wroks/contract_bean.dart';
import 'package:app/src/http/bean/wroks/customers_copyInfo.dart';
import 'package:app/src/ui/app_ui.dart';
import 'package:app/src/ui/route/works/public/items/ui_base.dart';
import 'package:app/src/ui/route/works/public/items/ui_card.dart';
import 'package:app/src/utils/image_path_utils.dart';

///附件
class UiAttachment {
  ///data 附件
  static Widget build(BuildContext context, List<Attachment>? data) {
    if (StringUtils.isEmpty(data)) {
      return AppUi.getEmptyView();
    }
    List<Widget> children = [];
    children.add(UiBase.title(context, AppStrings.of(context).Attachment)); //标题
    children.add(_items(context, data)); //数据
    var column = UiBase.column(context, children);
    var card = UiCard.build(context, column);
    return card;
  }

  static Widget _items(BuildContext context, List<Attachment>? data) {
    var listView = ListView.builder(
        shrinkWrap: true, //范围内进行包裹（内容多高ListView就多高）
        physics: NeverScrollableScrollPhysics(), //禁止滚动
        itemCount: data?.length ?? 0,
        itemBuilder: (context, index) {
          return Container(
            child: Row(
              children: _item(context, data?[index], index + 1),
            ),
            margin: EdgeInsets.only(top: 8),
          );
        });
    return listView;
  }

  static List<Widget> _item(
      BuildContext context, Attachment? data, int serial) {
    List<Widget> children = [];
    var serialView = _text(context, serial.toString() + "、"); //序号
    var fileNameView = _text(context, data?.FileName, isBlue: true); //文件名
    Expanded expanded = Expanded(
        child: Row(
      children: [
        SizedBox(
          child: serialView,
          width: 30,
        ),
        InkWell(
          child: fileNameView,
          onTap: () {
            data?.open(context); //打开文件
          },
        )
      ],
    ));
    children.add(expanded);
    children.add(_text(context, data?.StatusDescription)); //描述
    // children.add(Container(
    //   child: InkWell(
    //     child: Icon(Icons.share),
    //     onTap: () {
    //       data?.share(context); //文件分享
    //     },
    //   ),
    //   margin: EdgeInsets.only(left: 10),
    //   width: 50,
    // )); //分享；fixme 取消分享；王总提的，时间：2023.03.23
    return children;
  }

  static Widget _text(BuildContext context, String? str,
      {bool isBlue = false}) {
    TextStyle? style = null;
    if (isBlue) {
      style = AppStyle.textStyleWithCardBlue();
    } else {
      style = AppStyle.textStyleWithCard();
    }
    var text = Text(
      str?.trim() ?? "",
      style: style,
    );
    return Container(
      child: text,
      alignment: Alignment.centerLeft,
    );
  }
}
